package com.shawn.server.controller;

import com.shawn.model.dto.Answer;
import com.shawn.model.vo.QuestionnaireVo;
import com.shawn.model.vo.SoulResultVo;
import com.shawn.server.service.QuestionnaireService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 灵魂测试
 *
 * @author shawn
 * @date 2022年 11月 12日 16:28
 */
@Slf4j
@RestController
@RequestMapping("/testSoul")
public class QuestionnaireController {

    @Autowired
    private QuestionnaireService service;


    /**
     * 获取所有问卷
     *
     * @return {@link ResponseEntity}
     */
    @GetMapping
    public ResponseEntity getQuestionnaire(){
        List<QuestionnaireVo> list = service.getQuestionnaire();
        return ResponseEntity.ok(list);
    }

    /**
     * 提交问卷
     *
     * @param answers 答案
     * @return {@link ResponseEntity}
     */
    @PostMapping
    public ResponseEntity getAnswers(@RequestBody Map<String,List<Answer>> answers){
        String id =  service.checkAnswers(answers.get("answers"));
      return ResponseEntity.ok(id);
    }


    /**
     * 根据报告id查看测试结果
     *
     * @param id id
     * @return {@link ResponseEntity}
     */
    @GetMapping("/report/{id}")
    public ResponseEntity ViewingResult(@PathVariable String id){
        SoulResultVo vo = service.ViewingResult(id);
        return ResponseEntity.ok(vo);
    }
}
